<template>
  <div class="container">
    <!-- 导航栏主体 -->
    <div class="left-menu" :class="{ 'hide-menu': !isMenuOpen }">
      <div class="menu-header">公告</div>
      <div class="search-box">
        <input type="text" placeholder="搜索..." />
        <button>搜索</button>
      </div>
      <div class="menu-list">
        <div class="menu-item" v-for="(item, index) in menuItems" :key="index">
          {{ item }}
        </div>
      </div>
      <div class="article-list">
        <div class="article-list-header">
          <div class="article-list-title">文章榜单</div>
          <div class="article-list-refresh" @click="refreshArticleList">
            <i class="el-icon-refresh"></i> 换一换
          </div>
        </div>
        <div class="article-list-content">
          <div v-for="(article, index) in articleList" :key="index" class="article-item">
            <span class="article-index" :class="getIndexColor(index)">{{ index + 1 }}</span>
            <span class="article-title">{{ article.title }}</span>
          </div>
        </div>
      </div>
    </div>
    <!-- 展开与关闭导航区的模拟按键 -->
    <div class="open-close" :class="{ 'reverse-condition': !isMenuOpen }" @click="isMenuOpen = !isMenuOpen">&lt;</div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isMenuOpen: false,
      menuItems: [
        "全部博客",
        "后端",
        "前端",
        "大数据",
        "代码人生",
        "算法",
        "人工智能",
        "开发工具",
        "职场经验",
        "面试",
      ],
      articleList: [
        { title: "文章标题 1" },
        { title: "文章标题 2" },
        { title: "文章标题 3" },
        { title: "文章标题 4" },
        { title: "文章标题 5" },
      ],
    };
  },
  methods: {
    refreshArticleList() {
      // 刷新文章榜单的逻辑
      console.log("刷新文章榜单");
    },
    getIndexColor(index) {
      if (index === 0) return "orangered";
      if (index === 1) return "goldenrod";
      if (index === 2) return "dodgerblue";
      return "#666";
    },
  },
};
</script>

<style scoped>
.container {
  position: absolute;
  overflow-x: hidden;
}

.left-menu {
  position: fixed;
  top: 0;
  left: 0;
  width: 70%;
  height: 100vh;
  background-color: #f6f6f6;
  border-right: 2px solid white;
  text-align: center;
  font-size: 1.2rem;
  transition: transform 0.2s linear 0.1s;
  z-index: 999;
  overflow-y: auto;
}

.hide-menu {
  transform: translateX(-100%);
}

.menu-header {
  padding: 20px;
  font-size: 1.4rem;
  font-weight: bold;
}

.search-box {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px;
}

.search-box input {
  flex: 1;
  padding: 5px;
  border: 1px solid #ddd;
  border-radius: 4px 0 0 4px;
}

.search-box button {
  padding: 5px 10px;
  background-color: #007bff;
  color: #fff;
  border: none;
  border-radius: 0 4px 4px 0;
  cursor: pointer;
}

.menu-list {
  padding: 10px;
}

.menu-item {
  padding: 10px;
  cursor: pointer;
}

.article-list {
  padding: 10px;
}

.article-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid #ddd;
}

.article-list-title {
  font-size: 1.2rem;
  font-weight: bold;
}

.article-list-refresh {
  font-size: 0.8rem;
  color: #666;
  cursor: pointer;
}

.article-item {
  display: flex;
  align-items: center;
  padding: 10px 0;
}

.article-index {
  width: 20px;
  height: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  background-color: #666;
  color: #fff;
  font-size: 0.8rem;
  margin-right: 10px;
}

.article-title {
  flex: 1;
  font-size: 1rem;
  color: #333;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-content {
  margin-left: 70%;
  padding: 20px;
  transition: margin-left 0.2s linear 0.1s;
}

.hide-menu + .main-content {
  margin-left: 0;
}

.open-close {
  position: fixed;
  top: 50%;
  left: 70%;
  transform: translateY(-50%);
  width: 30px;
  height: 60px;
  background-color: #f6f6f6;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.5rem;
  font-weight: bold;
  cursor: pointer;
  transition: left 0.2s linear 0.1s;
  z-index: 998;
}

.reverse-condition {
  left: 0;
}
</style>